from runnd.lib.base import *
from formbuild import Form

class FormController(BaseController):
    def index(self):
        return Response('Not me!')

    def add(self):
        #all = model.User.select()
        #return Response(all)

        form = Form()
        c.formOpen = form.start(name="addUserForm", action="/form/process", method="post") + '\n'
        c.formBody = '<ol>\n'
        c.formBody += '<li><label for="userName">User Name</label>\n'
        c.formBody += form.field.text('userName') + '</li>\n'
        c.formBody += '<li><label for="password">Password</label>\n'
        c.formBody += form.field.text('password') + '</li>\n'
        c.formClose = form.field.submit(name="submit", value="submit") + '\n'
        c.formClose += form.end()

        return render_response('/addUserForm.mako')

    def process(self):
        """ Adds a user """
        userName = request.params['userName']
        password = request.params['password']
        person = model.User(userName, password)
        session_context.current.flush()
        h.redirect_to(action='result')

    def result(self):
        all = model.User.select()
        return Response(all)rom runnd.lib.base import *
